Skip to content

Catch potential exceptions during to string conversion #6042

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

cmb69
Copy link
Member

@cmb69 cmb69 commented Aug 25, 2020

As of PHP 7.4.0, exceptions are allowed to be thrown from inside
__toString() methods; we have to cater to that, and catch these
exceptions early.

Copy link
Member

@nikic nikic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks reasonable to me.

As of PHP 7.4.0, exceptions are allowed to be thrown from inside
`__toString()` methods; we have to cater to that, and catch these
exceptions early.
@cmb69 cmb69 force-pushed the cmb/com-tostring-ex branch from 3d177e3 to b67f4d5 Compare August 26, 2020 14:08
@@ -720,7 +728,9 @@ PHP_FUNCTION(com_event_sink)
if ((tmp = zend_hash_index_find(Z_ARRVAL_P(sink), 1)) != NULL && Z_TYPE_P(tmp) == IS_STRING)
dispname = Z_STRVAL_P(tmp);
} else if (sink != NULL) {
convert_to_string(sink);
if (!try_convert_to_string(sink)) {
return;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As these are in a PHP_FUNCTION you could use RETURN_THROWS()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yes, thanks! I'll do so when merging into master (PR targets PHP 7.4).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right I didn't see the target :)

@php-pulls php-pulls closed this in 2960301 Aug 27, 2020
@cmb69 cmb69 deleted the cmb/com-tostring-ex branch August 27, 2020 08:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants